<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<section class="content-header">
    <h1>
        库存划项目执行
    </h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" action="/material/ityToPro/exportExcel">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label>项目编号</label>
                                    <input type="text" name="ipmInProjectCode" id="ipmInProjectCode"
                                           class="form-control"
                                           placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label>项目名称</label>
                                    <input type="text" name="ipmInProjectName" class="form-control"
                                           id="ipmInProjectName"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label>标记人员</label>
                                    <input type="text" name="ipmProposer" id="ipmProposer"
                                           class="form-control"
                                           placeholder="请输入标记人员">
                                </div>
                                <div class="form-group">
                                    <label>
                                        状态
                                    </label>
                                    <select name="ipmAppStatus" class="form-control" id="ipmAppStatus">
                                        <option value="2" selected="selected">未执行</option>
                                        <option value="3">已执行</option>
                                        <option value="4">驳回</option>
                                        <option value="-1">全部</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>标记日期</label>
                                    <input type="text" class="form-control datepicker" name="startTimeQuery"
                                           id="startTimeQuery"
                                           readonly="readonly"/>
                                    <span>至</span>
                                    <input type="text" class="form-control datepicker" name="endTimeQuery"
                                           id="endTimeQuery"
                                           readonly="readonly"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn_search">搜索</button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="row" id="toolbar">
                    <div class="form-inline">
                        <button shiro:hasPermission="matinv:matwarproexec:edit" type="button"
                                class="btn btn-success"
                                id="btn-togetherCheck">
                            批量执行
                        </button>
<!--                        <button type="button" id="btn_exportExcel"-->
<!--                                shiro:hasPermission="matinv:matwaprorexec:view"-->
<!--                                class="btn btn-primary">-->
<!--                            导出-->
<!--                        </button>-->
                    </div>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    /** 单条执行 */
    function checkSingle(id) {
        js.modal.confirm("确定执行库存划项目吗？", function (result) {
            js.post({
                url: ctx + "material/ityToPro/checkSingle",
                data: {
                    ipmId: id
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            })
        })
    }

    /** 驳回 */
    function updateStatus(id, status) {
        js.modal.confirm("确定驳回项目划库存吗？", function (result) {
            js.post({
                url: ctx + "material/ityToPro/updateStatus",
                data: {
                    ipmId: id,
                    ipmAppStatus: status
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            })
        })
    }

    /** 单条撤销 */
    function cancelSingle(id) {
        js.modal.confirm("确定撤销库存划项目吗？", function (result) {
            js.post({
                url: ctx + "material/ityToPro/cancelSingle",
                data: {
                    ipmId: id
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            })
        })
    }

    $(function () {

        /** 加载列表 */
        table = js.table.init({
            url: ctx + "material/ityToPro/markList",
            pageSize: 300,
            queryData: {sourceFlgQuery: 2},
            columns: [
                {
                    field: "checked",
                    title: '全选',
                    checkbox: true,
                    formatter: function (value, row, index) {
                        if (row.ipmAppStatus === 2) {
                            return {
                                disabled: false
                            }
                        } else {
                            return {
                                disabled: true
                            }
                        }
                    }
                },
                {title: '物料描述', field: 'matNameDesc', width: '150'},
                {title: '在库数量', field: 'ityNum'},
                {title: '在库重量', field: 'ityWeight'},
                {title: '项目编号', field: 'ipmInProjectCode'},
                {title: '项目名称', field: 'ipmInProjectName', width: '200'},
                {title: '计划物料', field: 'ipmNameDescExcel'},
                {title: '标记数量', field: 'ipmNum'},
                {title: '标记重量', field: 'ipmWeight'},
                {title: '备注', field: 'ipmRemark'},
                {
                    title: '状态', field: 'ipmAppStatus', width: '100',
                    formatter: function (value, row, index) {
                        if (value === 2) {
                            return '<span class="badge bg-yellow">未执行</span> ';
                        } else if (value === 3) {
                            return '<span class="badge bg-green">已执行</span> ';
                        } else if (value === 4) {
                            return '<span class="badge bg-red">驳回</span> ';
                        }
                    }
                },
                {title: '标记人员', field: 'ipmProposer'},
                {title: '标记时间', field: 'ipmDate'},
                {title: '库位', field: 'whiName'},
                {
                    title: '操作', width: '110',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (hasP("matinv:matwarproexec:edit")) {
                            if (row.ipmAppStatus === 2) {
                                actions.push('<a style="margin-right: 5px" class="btn btn-success btn-xs" href="javascript:void(0);" onclick="checkSingle(' + row.ipmId + ')" >执行</a>');
                                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="updateStatus(' + row.ipmId + ',4)"> 驳回</a>');
                            } else if (row.ipmAppStatus === 3) {
                                actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="cancelSingle(' + row.ipmId + ')"> 撤销</a>');
                            }
                        }
                        return actions.join('');
                    }
                }
            ]
        });

        /** 表格搜索 */
        $("#btn_search").click(function () {
            js.table.search(table);
        });

        /** 批量执行 */
        $("#btn-togetherCheck").click(function () {

            var rows = js.table.selectRows("bootstrap-table");

            // 如果没有选择，显示提示信息
            if (rows.length == 0) {
                js.modal.warning("请至少选择一条明细");
                return false;
            } else {
                var arr = js.table.selectColumns(table, "ipmId");
                js.post({
                    url: ctx + "material/ityToPro/checkTogether",
                    contentType: "application/json",
                    data: JSON.stringify(arr),
                    success: function (result) {
                        if (result.type === web_status.SUCCESS) {
                            js.modal.success(result.msg);
                            js.table.refresh(table);
                        } else {
                            js.modal.warning(result.msg);
                            js.table.refresh(table);
                        }
                        js.modal.closeLoading();
                    }
                })
            }
        });

        /**
         * 导出Excel
         */
        $("#btn_exportExcel").click(function () {

            // // 判断表单数据是否为空,为空不允许导出
            // var isAllEmpty = true;
            // var t = $('#queryForm').serializeArray();
            // $.each(t, function (i, item) {
            //     if (item['name'] == 'ipmAppStatus' && item['value'] == -1) {
            //         js.modal.warning("请填写非日期类导出筛选条件！");
            //         return false;
            //     } else if ((item['name'] != 'startTimeQuery' && item['value'] != '') || (item['name'] != 'endTimeQuery' && item['value'] != '')) {
            //         isAllEmpty = false;
            //     }
            // });
            // if (isAllEmpty) {
            //     $("#ipmInProjectCode").focus();
            //     js.modal.warning("请填写非日期类导出筛选条件！");
            //     return false;
            // }
            // if($('#ipmAppStatus').val() == '-1'){
            //     $("#ipmInProjectCode").focus();
            //     js.modal.warning("不可导出全部状态记录！");
            //     return false;
            // }
            // if ($('#ipmInProjectCode').val() == '' && $('#ipmInProjectName').val() == ''
            //     && $('#ipmProposer').val() == ''){
            //     $("#ipmInProjectCode").focus();
            //     js.modal.warning("请填写非日期类导出筛选条件！");
            //     return false;
            // }

            $("#queryForm").submit();
        });

    })

</script>
</body>
</html>